home *** CD-ROM | disk | FTP | other *** search
- # include "MWMapInfo.h"
- # include "MakeWrite.h"
-
-
- /*
- * Initialize a MapSpec by allocating a mark string for it.
- */
-
- void
- InitMSpec (MapSpec *mSpec)
- {
- mSpec->mark = (StringHandle) NewHandle ((Size) maxMarkLen + 1);
- }
-
-
- /*
- * Terminate a MapSpec by tossing its mark string. The procedure
- * name is somewhat of a misnomer since it doesn't actually dispose
- * of the MapSpec itself.
- */
-
- void
- TermMSpec (MapSpec *mSpec)
- {
- DisposeHandle ((Handle) mSpec->mark);
- }
-
-
- /*
- * Copy one init'ed MapSpec to another. The most difficult part
- * is making sure the mark string gets copied correctly.
- */
-
- void
- CopyMSpec (MapSpec *srcMSpec, MapSpec *dstMSpec)
- {
- StringHandle srcStr, dstStr;
-
- dstStr = dstMSpec->mark; /* save, since next line clobbers it */
- *dstMSpec = *srcMSpec;
- dstMSpec->mark = dstStr; /* fix this field and copy the handle */
- srcStr = srcMSpec->mark;
- HLock ((Handle) srcStr);
- HLock ((Handle) dstStr);
- CopyString (*srcStr, *dstStr);
- HUnlock ((Handle) srcStr);
- HUnlock ((Handle) dstStr);
- /*SetHandleSize (dstStr, (Size) 0);
- HandAndHand (srcMSpec->mark, dstStr);*/
- }
-
-
- /*
- * Zero the contents of an init'ed MapSpec.
- */
-
- void
- ClearMSpec (MapSpec *mSpec)
- {
- mSpec->font = sameFont;
- mSpec->size = sameSize;
- mSpec->style = sameStyle;
- (*mSpec->mark)[0] = 0;
- mSpec->selStart = 0;
- mSpec->selEnd = 0;
- }
-
-
- /*
- * Compare two markers for equality.
- */
-
- short
- CompareMark (StringHandle s1, StringHandle s2)
- {
- short result;
-
- HLock ((Handle) s1);
- HLock ((Handle) s2);
- result = CompareString (*s1, *s2);
- HUnlock ((Handle) s1);
- HUnlock ((Handle) s2);
- return (result);
- }
-
-
- /*
- * Compare two map specifications.
- * Return:
- * 0 m1 = m2
- * < 0 m1 < m2
- * > 0 m1 > m2
- *
- * Mark sorts before font, which sorts before size, which sorts
- * before style.
- *
- * For all of font, size and style, the "same" selection is greater,
- * so that generic selections sort to the end of the list. Font
- * comparisons are otherwise based on the name of the font, rather
- * than its number. A string compare is avoided by keeping the
- * fonts in alphabetic order in the font information structures.
- *
- * Note that the style comparison does not use the manifest constants
- * defined for each style value, and so would break if style coding
- * changed!
- */
-
- short
- CompareMSpec (MapSpec *m1, MapSpec *m2)
- {
- short i;
- short s1, s2;
-
- if ((i = CompareMark (m1->mark, m2->mark)) != 0)
- return (i);
-
- if (m1->font != m2->font)
- {
- if (m1->font == sameFont)
- return (1);
- if (m2->font == sameFont)
- return (-1);
- return (FontIndex (m1->font) - FontIndex (m2->font));
- }
-
- if ((i = m1->size - m2->size) != 0)
- {
- if (m1->size == sameSize)
- return (1);
- if (m2->size == sameSize)
- return (-1);
- return (i);
- }
-
- s1 = m1->style;
- s2 = m2->style;
- if (s1 - s2 != 0)
- {
- if (s1 == sameStyle)
- return (1);
- if (s2 == sameStyle)
- return (-1);
- for (i = 0; i < 7; ++i)
- {
- if (s1 == 0)
- {
- if (s2 != 0)
- return (-1);
- }
- else if (s2 == 0)
- {
- return (1);
- }
- else if (s1 & 1)
- {
- if (!(s2 & 1))
- return (-1);
- }
- else if (s2 & 1)
- return (1);
- s1 >>= 1;
- s2 >>= 1;
- }
- }
- return (0); /* equal */
- }
-
-
- /*
- * Convert map specs to map text. Do this by converting input specs
- * and output specs.
- */
-
- void
- MSpecToMStr (MapSpec *mSpec, MapStr *mStr)
- {
- HLock ((Handle) mSpec->mark);
- CopyString (*mSpec->mark, mStr->markStr);
- HUnlock ((Handle) mSpec->mark);
- FontToStr (mSpec->font, mStr->fontStr);
- SizeToStr (mSpec->size, mStr->sizeStr);
- StyleToStr (mSpec->style, mStr->styleStr);
- }
-
-
- /*
- * Convert font number to font name. The font *must* be legal.
- */
-
- void
- FontToStr (short font, StringPtr str)
- {
- FontName (FontIndex (font), str);
- }
-
-
- /*
- * Convert size value to string.
- */
-
- void
- SizeToStr (short size, StringPtr str)
- {
- if (size == sameSize) /* no size specified, use default */
- CopyString ("\pSame", str);
- else
- NumToString ((long) size, str);
- }
-
-
- /*
- * Convert style value to string. If the style has only one attribute
- * bit set, use the attribute name, otherwise use abbreviated form with
- * one letter for each attribute.
- */
-
- static StringPtr styleStr[7] =
- {
- "\pBold",
- "\pItalic",
- "\pUnder",
- "\pOutline",
- "\pShadow",
- "\pHigh",
- "\pLow"
- };
-
-
- void
- StyleToStr (short style, StringPtr str)
- {
- short i, style2;
-
- if (style == sameStyle) /* no style specified, use default */
- CopyString ("\pSame", str);
- else if (style == 0) /* no bits set = plain text */
- CopyString ("\pPlain", str);
- else
- {
- style2 = style;
- for (i = 0; i < 7; ++i)
- {
- if ((style2 & 1))
- {
- if (style2 != 1)
- break; /* more than 1 bit set */
- CopyString (styleStr[i], str);
- return;
- }
- style2 >>= 1;
- }
- i = 0;
- if (style & styleBold)
- str[++i] = 'B';
- if (style & styleItalic)
- str[++i] = 'I';
- if (style & styleUnder)
- str[++i] = 'U';
- if (style & styleOutline)
- str[++i] = 'O';
- if (style & styleShadow)
- str[++i] = 'S';
- if (style & styleSuper)
- str[++i] = 'H';
- if (style & styleSub)
- str[++i] = 'L';
- str[0] = i;
- }
- }
-